﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.SessionState;
using HNQXYJ.Model;
namespace HNQXYJ.BLL
{
    /// <summary>
    /// County 的摘要说明
    /// </summary>
    public class County : IHttpHandler, IRequiresSessionState 
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string action = context.Request["action"];
            string id = context.Request["id"];
            if (action == "GetCountyList")
            {
                string cityCode = context.Request["cityCode"];
                CountyBLL cb = new CountyBLL();
                List<HCounty> list = cb.GetCountyListByParentCode(cityCode);
                JavaScriptSerializer jss = new JavaScriptSerializer();
                context.Response.Write(jss.Serialize(list));
               //context.Response.Write("Hello World");
            }

            //根据id删除一个县
            if (id != "")
            {
                int Id = Convert.ToInt32(id);
                int res = new CountyBLL().DeleteCountyById(Id);
                if (res > 0)
                {
                    context.Response.Redirect("../HN_City/CountyMgr.aspx");
                }
            }

            //获取一个县区对象（根据session值）
            if (action == "GetOneCounty")
            {
                string selfCode = context.Session["ranklevel"].ToString();
                HCounty county = new CountyBLL().GetCountyBySelfCode(selfCode);
                JavaScriptSerializer jss = new JavaScriptSerializer();
                context.Response.Write(jss.Serialize(county));
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}